package com.fishingwithme.android.ui.viewmodels

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.fishingwithme.android.data.model.MySpotDto
import com.fishingwithme.android.data.repository.FishingRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class MySpotsViewModel @Inject constructor(
    private val repository: FishingRepository
) : ViewModel() {
    
    fun getSpots(isCollected: Boolean): Flow<PagingData<MySpotDto>> {
        Log.d("MySpotsViewModel", "Creating pager for isCollected: $isCollected")
        return Pager(
            config = PagingConfig(
                pageSize = 10,
                enablePlaceholders = false
            ),
            pagingSourceFactory = {
                Log.d("MySpotsViewModel", "Creating MySpotsPagingSource for isCollected: $isCollected")
                MySpotsPagingSource(repository, isCollected)
            }
        ).flow.cachedIn(viewModelScope)
    }
}